//package com.hsylient.translator.gpt;
//
//import cn.hutool.json.JSONUtil;
//import com.alibaba.fastjson2.JSON;
//import okhttp3.*;
//
//import java.io.IOException;
//import java.net.InetSocketAddress;
//import java.net.Proxy;
//import java.nio.charset.StandardCharsets;
//import java.util.concurrent.TimeUnit;
//
//public class GPTUtil2 {
//
//    private static final String GPT_API_URL = "https://api.openai.com/v1/chat/completions";
//    private static final String API_KEY = "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";
//    private static final String MY_API_KEY = "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";
//
//
//    private static final String CONTENT_TYPE = "application/json";
//
//    private static final String PROXY_HOST = "127.0.0.1";
//    private static final int PROXY_PORT = 7890;
//
//
//    public static OkHttpClient client() {
//        return new OkHttpClient.Builder()
//                .connectTimeout(5, TimeUnit.SECONDS)
//                .writeTimeout(150, TimeUnit.SECONDS)
//
//                .readTimeout(150, TimeUnit.SECONDS)
//                .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT)))
//                .build();
//    }
//
//    public static Request request(GPTRequestBody body) {
//        return new Request.Builder()
//                .url(GPT_API_URL)
//                .addHeader("Authorization", "Bearer " + MY_API_KEY)
//                .addHeader("Content-Type", CONTENT_TYPE)
//                .post(RequestBody.create(MediaType.parse(CONTENT_TYPE), JSON.toJSONString(body)))
//                .build();
//    }
//
//    public static Response call(String message) throws IOException {
//        return client().newCall(request(GPTRequestBody.instance(message))).execute();
//    }
//
//    public static GptResponse callParseResponse(String message) {
//        Response response;
//        String nowString;
//        try {
//            response = client().newCall(request(GPTRequestBody.instance(message))).execute();
//            assert response.body() != null;
//            nowString = new String(response.body().bytes(), StandardCharsets.UTF_8);
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//        return JSONUtil.toBean(nowString, GptResponse.class);
//    }
//}
